﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMK.Framework.Model.Cond;
using XMK.Framework.Model;
using XMK.Framework.DataAccess;
using XMK.Framework.Config;
using XMK.Framework.Data;



namespace XMK.Framework.Biz
{
    /// <summary>
    /// 存储过程业务处理
    /// </summary>
    public class PorcBiz
    {
        /// <summary>
        /// 执行入口
        /// </summary>
        /// <param name="wsid"></param>
        /// <param name="paras"></param>
        /// <param name="order"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public static object Exec(DbProvider dbProvider,string wsid,Dictionary<string,object> paras,OrderInfo order,PageInfo page)
        {
            ProcData data = new ProcData(dbProvider);
            Dictionary<string, List<ProcInfo>> dict = data.GetWsProcInfosDict();

            if (dict.ContainsKey(wsid))
            {
                List<ProcInfo> list = dict[wsid];
                // 单个存储过程
                if (list.Count == 1)
                {
                    ProcInfo proc = list[0];
                    return DataHelper.ExecProc(proc, paras, order, page);
                }
                else
                {
                    // 多个
                    for (int i = 0; i < list.Count; i++)
                    {
                        // 如果有对应的parakey
                        if (!string.IsNullOrEmpty(list[i].ParaKey))
                        {
                            list[i].ParaValueDict = (Dictionary<string, object>)paras[list[i].ParaKey];
                        }
                        else
                        {
                            list[i].ParaValueDict = paras;
                        }
                    }
                   return DataHelper.ExecProc(list);
                }
            
            }
            return null;
        }
    }
}
